Finish hooking up all the UI for preferences.
authorrobertl <robertl>
Mon, 15 Feb 2010 02:57:00 +0000 (02:57 +0000)
committerrobertl <robertl>
Mon, 15 Feb 2010 02:57:00 +0000 (02:57 +0000)
gui/babeldata.h
gui/format.h
gui/mainwindow.cpp
gui/preferences.cpp
gui/preferences.h
gui/preferences.ui
gui/setting.h
gui/upgrade.cpp
gui/upgrade.h

index 540e729fbe38b8eced12fe23e6d33a45da45d130..5f87fb5a47fc74cd937c061a3a9db90ebe4d4471 100644 (file)
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-// $Id: babeldata.h,v 1.4 2010/02/14 05:33:36 robertl Exp $
+// $Id: babeldata.h,v 1.5 2010/02/15 02:57:00 robertl Exp $
 //------------------------------------------------------------------------
 //
 //  Copyright (C) 2009  S. Khai Mong <khai@mangrai.com>.
@@ -57,7 +57,8 @@ public:
     upgradeCheckMethod(0),
     upgradeCheckTime(QDateTime(QDate(2001, 1, 1), QTime(0, 0))),
     installationUuid(QUuid::createUuid().toString()),
-    checkUpgradeOnStart(true)
+    startupVersionCheck(true),
+    reportStatistics(true)
   {
   };
   
@@ -100,6 +101,11 @@ public:
     sg.addVarSetting(new IntSetting("app.upgradeCheckMethod", upgradeCheckMethod));
     sg.addVarSetting(new DateTimeSetting("app.upgradeCheckTime", upgradeCheckTime));
     sg.addVarSetting(new StringSetting("app.installationUuid", installationUuid));
+
+    // Global preferences.
+    sg.addVarSetting(new BoolSetting("app.startupVersionCheck", startupVersionCheck));
+    sg.addVarSetting(new BoolSetting("app.reportStatistics", reportStatistics));
+
   }
 
   static const int noType;
@@ -137,7 +143,8 @@ public:
   QString installationUuid;
 
   // Global preferences.
-  bool checkUpgradeOnStart;
+  bool startupVersionCheck;
+  bool reportStatistics;
 
 };
 
index b78b15215aa10467bb6ed9f3289022c8e3e69ea5..e83d2682ca1f176f48e8e95f8e216e1fa18afb97 100644 (file)
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-// $Id: format.h,v 1.5 2010/02/14 05:33:37 robertl Exp $
+// $Id: format.h,v 1.6 2010/02/15 02:57:00 robertl Exp $
 //------------------------------------------------------------------------
 //
 //  Copyright (C) 2009  S. Khai Mong <khai@mangrai.com>.
@@ -185,7 +185,9 @@ class Format
 
   bool isDeviceFormat() const { return deviceFormat; };
   bool isFileFormat() const { return   fileFormat; };
+
   bool isHidden() const { return hidden_; };
+  void setHidden(bool state) { hidden_ = state; };
   
   void saveSettings(QSettings &settings);
   void restoreSettings(QSettings &settings);
index dc8d0a9b7b14bbbd8d830c1971ce5d569870b9aa..42b5a883627e3828d422f3df81d18233f70ceef9 100644 (file)
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-// $Id: mainwindow.cpp,v 1.15 2010/02/14 21:29:06 robertl Exp $
+// $Id: mainwindow.cpp,v 1.16 2010/02/15 02:57:00 robertl Exp $
 //------------------------------------------------------------------------
 //
 //  Copyright (C) 2009  S. Khai Mong <khai@mangrai.com>.
@@ -172,10 +172,11 @@ MainWindow::MainWindow(QWidget* parent): QMainWindow(parent)
   //--- Restore from registry
   restoreSettings();
 
-  if (bd.checkUpgradeOnStart) {
+  if (bd.startupVersionCheck) {
     upgrade = new UpgradeCheck(parent, formatList);
     upgrade->checkForUpgrade(babelVersion, bd.upgradeCheckMethod, 
-                             bd.upgradeCheckTime, bd.installationUuid);
+                             bd.upgradeCheckTime, bd.installationUuid,
+                             bd.reportStatistics);
   }
 }
 
@@ -252,7 +253,6 @@ void MainWindow::inputFileOptBtnClicked()
   ui.inputFormatCombo->clear();
   for (int i=0; i<indices.size(); i++) {
     int k = indices[i];
-fprintf(stderr, "%s/%d\n", qPrintable(formatList[k].getName()), formatList[k].isHidden());
     if (!formatList[k].isHidden())
       ui.inputFormatCombo->addItem(formatList[k].getDescription(), QVariant(k));
   }
@@ -270,7 +270,6 @@ void MainWindow::inputDeviceOptBtnClicked()
   ui.inputFormatCombo->clear();
   for (int i=0; i<indices.size(); i++) {
     int k = indices[i];
-fprintf(stderr, "%s/%d\n", qPrintable(formatList[k].getName()), formatList[k].isHidden());
     if (!formatList[k].isHidden())
       ui.inputFormatCombo->addItem(formatList[k].getDescription(), QVariant(k));
   }
@@ -965,8 +964,11 @@ void MainWindow::aboutActionX()
 //------------------------------------------------------------------------
 void MainWindow::preferencesActionX()
 {
-  Preferences preferences(0, formatList);
+  Preferences preferences(0, formatList, bd);
   preferences.exec();
+
+  // We may have changed the list of displayed formats.  Resynchronize.
+  setWidgetValues();
 }
 
 
index a5307ba8eca654ac2841284407b92e0fbbf2f771..3d01dfd3c134264fd0ac2acad421c2c0e889e019 100644 (file)
@@ -17,7 +17,6 @@
 //  USA
 
 
-#include <QSettings>
 #include "preferences.h"
 
 class FormatListEntry : public QListWidgetItem {
@@ -32,13 +31,16 @@ class FormatListEntry : public QListWidgetItem {
    Format& fmt_;
 };
 
-Preferences::Preferences(QWidget* parent, QList<Format>& formatList) :
-  formatList_(formatList)
+Preferences::Preferences(QWidget* parent, QList<Format>& formatList,
+                         BabelData& bd) : QDialog(parent),
+  formatList_(formatList),
+  bd_(bd)
 {
   ui_.setupUi(this);
 
-  // TODO: read from prefs.
-  // ui_.startupCheck->setChecked(true);
+  ui_.startupCheck->setChecked(bd_.startupVersionCheck);
+  ui_.reportStatisticsCheck->setChecked(bd_.reportStatistics);
+
   connect (ui_.buttonBox, SIGNAL(accepted()), this, SLOT(acceptClicked()));
   connect (ui_.buttonBox, SIGNAL(rejected()), this, SLOT(rejectClicked()));
 
@@ -48,7 +50,7 @@ Preferences::Preferences(QWidget* parent, QList<Format>& formatList) :
   for (int i = 0; i < formatList_.size(); i++) {
     FormatListEntry *item = new FormatListEntry(formatList[i]);
 
-    ui_.enabledFormatsList->insertItem(0, item);
+    ui_.enabledFormatsList->addItem(item);
   }
 }
 
@@ -70,6 +72,13 @@ void Preferences::disableAllClicked()
 
 void Preferences::acceptClicked()
 {
+  for (int i = 0; i < ui_.enabledFormatsList->count(); i++) {
+    QListWidgetItem* item = ui_.enabledFormatsList->item(i);
+    formatList_[i].setHidden(item->checkState() == Qt::Unchecked);
+  }
+
+  bd_.startupVersionCheck = ui_.startupCheck->isChecked();
+  bd_.reportStatistics = ui_.reportStatisticsCheck->isChecked();
   accept();
 }
 
index 15c95aa7ecb5814642d16b9c22f2b2a672810728..d934752c7505a240b40474ef3fcff539a5062e4c 100644 (file)
 //  USA
 
 #include "ui_preferences.h"
+
+#include "babeldata.h"
 #include "format.h"
 
 class Preferences : public QDialog {
   Q_OBJECT
 
  public:
-  Preferences(QWidget* parent, QList<Format>& formatList);
+  Preferences(QWidget* parent, QList<Format>& formatList, BabelData& bd);
 
  private:
   QList<Format>& formatList_;
   Ui_Preferences ui_;
+  BabelData& bd_;
 
  private slots:
   void enableAllClicked();
index 6ed33529ebfc39a78ca269ba8609d2c4207e664f..6b44e9083d61e85ac625ec83d5a594845ad58075 100644 (file)
@@ -6,12 +6,12 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>777</width>
-    <height>351</height>
+    <width>554</width>
+    <height>404</height>
    </rect>
   </property>
   <property name="sizePolicy">
-   <sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
+   <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
     <horstretch>0</horstretch>
     <verstretch>0</verstretch>
    </sizepolicy>
   <layout class="QFormLayout" name="formLayout">
    <item row="0" column="0">
     <widget class="QTabWidget" name="tabWidget">
-     <property name="sizePolicy">
-      <sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
-       <horstretch>0</horstretch>
-       <verstretch>0</verstretch>
-      </sizepolicy>
-     </property>
      <property name="currentIndex">
       <number>1</number>
      </property>
           <property name="text">
            <string>Check for newer version on start.</string>
           </property>
-          <property name="checked">
-           <bool>true</bool>
-          </property>
          </widget>
         </item>
         <item>
-         <widget class="QCheckBox" name="checkBox">
+         <widget class="QCheckBox" name="reportStatisticsCheck">
           <property name="text">
            <string>Anonymously report usage data.</string>
           </property>
-          <property name="checked">
-           <bool>true</bool>
-          </property>
          </widget>
         </item>
        </layout>
          </item>
          <item>
           <widget class="QListWidget" name="enabledFormatsList">
+           <property name="sizePolicy">
+            <sizepolicy hsizetype="MinimumExpanding" vsizetype="Expanding">
+             <horstretch>0</horstretch>
+             <verstretch>0</verstretch>
+            </sizepolicy>
+           </property>
            <property name="sortingEnabled">
-            <bool>true</bool>
+            <bool>false</bool>
            </property>
           </widget>
          </item>
index a0902cda10f1673ee4f3c53bf462f79e833830ed..2003c9e3088abb8b163233dc3cebab184bf0a311 100644 (file)
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-// $Id: setting.h,v 1.2 2009/09/02 19:05:27 robertl Exp $
+// $Id: setting.h,v 1.3 2010/02/15 02:57:00 robertl Exp $
 //------------------------------------------------------------------------
 //
 //  Copyright (C) 2009  S. Khai Mong <khai@mangrai.com>.
@@ -24,6 +24,7 @@
 #define SETTING_H
 
 #include <QSettings>
+#include <QDate>
 
 
 //------------------------------------------------------------------------
index 22613fd4d0d85c3e46e21d548c5a541ebe16e8cf..b88a81e903e3ddb442719d4f5faffa97ad7b783b 100644 (file)
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-// $Id: upgrade.cpp,v 1.21 2010/02/14 21:29:06 robertl Exp $
+// $Id: upgrade.cpp,v 1.22 2010/02/15 02:57:00 robertl Exp $
 /*
     Copyright (C) 2009, 2010  Robert Lipe, robertlipe@gpsbabel.org
 
@@ -115,7 +115,8 @@ QString UpgradeCheck::getOsVersion()
 UpgradeCheck::updateStatus UpgradeCheck::checkForUpgrade(const QString &currentVersionIn,
                int checkMethod,
                const QDateTime &lastCheckTime,
-               const QString &installationUuid)
+               const QString &installationUuid,
+               bool reportStatistics)
 {
   currentVersion = currentVersionIn;
   currentVersion.remove("GPSBabel Version ");
@@ -168,7 +169,7 @@ UpgradeCheck::updateStatus UpgradeCheck::checkForUpgrade(const QString &currentV
     if (wc)
       args += QString("&uc%1=wr/%2/%3").arg(j++).arg(formatName).arg(wc);
   }
-  if (j)
+  if (j && reportStatistics)
     args += QString("&uc=%1").arg(j);
 
   if (false && testing)
index 523e7561586dd574028694e826e4775176109add..32623317d12f597ac988ba110a8e0632339b7764 100644 (file)
@@ -43,7 +43,8 @@ public:
   UpgradeCheck::updateStatus checkForUpgrade(const QString &babelVersion, 
                                             int upgradeCheckMethod,
                                             const QDateTime &lastCheckTime,
-                                            const QString &installationUuid
+                                            const QString &installationUuid,
+                                             bool reportStatistics
                                              );
   QDateTime getUpgradeWarningTime() {
     return upgradeWarningTime;